package com.sphd.education.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sphd.education.R;
import com.sphd.education.info.ClassifyOne;

import java.util.List;

/**
 * Created by Administrator on 2015/10/16.
 */
public class ClassifyAdapter extends BaseAdapter {
    private Context context;
    private List<ClassifyOne> classifyOneList;
    private int layoutInt;
    private int selectedPosition = -1;// 选中的位置
    public ClassifyAdapter(Context context, List<ClassifyOne> classifyOneList, int layoutInt) {
        this.context = context;
        this.classifyOneList = classifyOneList;
        this.layoutInt = layoutInt;
    }
    public void setSelectedPosition(int position) {
        selectedPosition=position;
    }
    @Override
    public int getCount() {
        return classifyOneList.size();
    }

    @Override
    public Object getItem(int position) {
        return classifyOneList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewClassify viewClassify=null;
        if(viewClassify==null){
            viewClassify= new ViewClassify();
            convertView= View.inflate(context,layoutInt,null);
            viewClassify.fenlei = (TextView) convertView.findViewById(R.id.classify_one_textview);
            viewClassify.linearLayoutList= (LinearLayout) convertView.findViewById(R.id.LinearLayoutList);
            convertView.setTag(viewClassify);
        }else{
            viewClassify= (ViewClassify) convertView.getTag();
        }
        if (selectedPosition == position) {
            viewClassify.fenlei.setSelected(true);
            viewClassify.fenlei.setPressed(true);
            viewClassify.linearLayoutList.setBackgroundColor(context.getResources().getColor(R.color.my_gr));
        } else {
            viewClassify.fenlei.setSelected(false);
            viewClassify.fenlei.setPressed(false);
            viewClassify.linearLayoutList.setBackgroundColor(Color.TRANSPARENT);
        }
        viewClassify.fenlei.setText(classifyOneList.get(position).getClassify());
        return convertView;
    }



    class ViewClassify{
        TextView fenlei;
        LinearLayout linearLayoutList;
    }

}
